package caffeine;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.time.Duration;

/**
 * @author brianxia
 * @version 1.0
 * @date 2022-10-25 9:35
 */
public class Test2 {

    public static void main(String[] args) throws InterruptedException {
        Cache<String, String> cache = Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(2)).build();

        cache.put("123","456");
        cache.put("a","b");

        System.out.println( cache.getIfPresent("123"));
        System.out.println( cache.getIfPresent("a"));
        System.out.println( cache.getIfPresent("b"));

        Thread.sleep(3000L);

        System.out.println( cache.getIfPresent("123"));
        System.out.println( cache.getIfPresent("a"));
        System.out.println( cache.getIfPresent("b"));
    }
}
